import { DailyItem } from "./DailyItem";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { Language } from "../../../../../extend/language/Language";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { LongProgressBar } from "../../player/LongProgressBar";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { DailyInfo } from "../../../model/DailyInfo";
import { LoaderManager } from "../../../../../com/gengine/resource/LoaderManager";
import { ImageInfo } from "../../../../../com/gengine/resource/info/ImageInfo";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
//class DailyWelfareItem
    
    export  class DailyWelfareItem extends DailyItem
    {
        constructor()
        {
            super();
            return;
        }

        public /* override */ initUI(): void
        {
            super.initUI();
            ObjCreate.createBitmap(ImagesConst.AchievementIconBg, 10, 4, this);
            this._iconBmp = new Object /* flash.display.Bitmap */();
            this._iconBmp.x = 15;
            this._iconBmp.y = 9;
            addChild(this._iconBmp);
            _itemName.x = 65;
            _itemName.y = 5;
            _itemName.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._itemDes = ObjCreate.createGTextField("", 65, 25, 600, 20, this, null, false);
            var loc1=ObjCreate.createGTextField(Language.getString(20977), 200, 5, 300, 20, this, GlobalStyle.textFormat5, false);
            this._prograssBar = new LongProgressBar();
            this._prograssBar.x = loc1.x + loc1.textWidth;
            this._prograssBar.y = 7;
            this._prograssBar.progressBarClass = ImagesConst.EnergyBar;
            this._prograssBar.setBgSize(180, 14);
            this._prograssBar.setValue(5, 10);
            addChild(this._prograssBar);
            this._optBtn = ObjCreate.createGButton("", 540, 15, 80, 25, this, "ButtonRed");
            this._optBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOptBtnClickHandler);
            this._completeIcon = new Object /* flash.display.Bitmap */();
            this._completeIcon.x = 480;
            this._completeIcon.y = 17;
            LoaderHelp.addResCallBack(ResFileConst.daily, this.onDailyResLoadedHandler);
            addChild(this._completeIcon);
            return;
        }

        /* internal  */onDailyResLoadedHandler(): void
        {
            this._completeIcon.bitmapData = GlobalClass.getBitmapData(ImagesConst.DailyComIcon);
            return;
        }

        public /* override */ updateData(arg1: DailyInfo): void
        {
            super.updateData(arg1);
            if (arg1 == null) 
            {
                return;
            }
            this._optBtn.enabled = true;
            this._completeIcon.visible = false;
            _itemName.textColor = 16187136;
            this._itemDes.htmlText = arg1.des;
            this._optBtn.label = arg1.rewardDes;
            this._prograssBar.setValue(arg1.count, arg1.countTotal);
            LoaderManager.instance.load(arg1.url, this.onResLoaded);
            if (arg1.count >= arg1.countTotal) 
            {
                this._optBtn.enabled = false;
                this._completeIcon.visible = true;
            }
            if (arg1.condition == 1) 
            {
                this._optBtn.enabled = false;
                this._completeIcon.visible = false;
            }
            _itemLevel.text = "";
            _itemTime.text = "";
            _itemOpt.text = "";
            return;
        }

        /* internal  */onResLoaded(arg1: ImageInfo): void
        {
            this._iconBmp.bitmapData = arg1.bitmapData;
            this._iconBmp.width = 36;
            this._iconBmp.height = 36;
            return;
        }

        public /* override */ get height(): number
        {
            return 55;
        }

        public /* override */ get width(): number
        {
            return 642;
        }

        /* internal  */onOptBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.DailyEveryDayActiveOpt, _info));
            return;
        }

        /* internal */ /* var */_iconBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_optBtn: GButton;

        /* internal */ /* var */_itemDes: GTextFiled;

        /* internal */ /* var */_prograssBar: LongProgressBar;

        /* internal */ /* var */_completeIcon: Object /* flash.display.Bitmap */;
    }
